package com.gpnu7_412.yanzhi.util;

import com.gpnu7_412.yanzhi.status.Impl.ResultCode;
import com.gpnu7_412.yanzhi.status.StatusCode;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author ZZH
 */
@Data
@AllArgsConstructor
public class Result {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 提示信息
     */
    private String msg;
    /**
     * 数据
     */
    private Object data;

    /**
     * 手动设置返回
     */
    public Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 默认返回成功
     */
    public Result() {
        this.code = ResultCode.SUCCESS.getCode();
        this.msg = ResultCode.SUCCESS.getMessage();
        this.data = null;
    }

    /**
     * 只返回状态码
     * @param statusCode 状态码
     */
    public Result(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMessage();
        this.data = null;
    }

    /**
     * 默认返回成功状态码，数据对象
     * @param data 返回数据
     */
    public Result(Object data) {
        this.code = ResultCode.SUCCESS.getCode();
        this.msg = ResultCode.SUCCESS.getMessage();
        this.data = data;
    }

    /**
     * 返回指定状态码，提示信息
     * @param statusCode 状态码
     * @param msg 提示信息
     */
    public Result(StatusCode statusCode, String msg) {
        this.code = statusCode.getCode();
        this.msg = msg;
//        this.msg = statusCode.getMessage();
//        this.data = msg;
    }

    public Result(StatusCode statusCode, String msg, Object data) {
        this.code = statusCode.getCode();
        this.msg = msg;
        this.data = data;
    }
}
